package interfaz;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Login implements IVista {

	private JFrame frmLogin;
	private JTextField txtId;
	private JButton btnLogin;
	private JButton btnRegistro;
	
	private JPasswordField txtPassword;

	/**
	 * Create the application.
	 */
	public Login() {
		initialize();
	}
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmLogin = new JFrame();
		frmLogin.setResizable(false);
		frmLogin.setTitle("Fixpack");
		frmLogin.getContentPane().setBackground(Color.WHITE);
		frmLogin.setBackground(Color.WHITE);
		frmLogin.setBounds(100, 100, 450, 301);
		frmLogin.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 25, 25, 25, 25};
		gridBagLayout.columnWeights = new double[]{1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmLogin.getContentPane().setLayout(gridBagLayout);
		
		btnRegistro = new JButton("Registro");
		
		GridBagConstraints gbc_btnRegistro = new GridBagConstraints();
		gbc_btnRegistro.insets = new Insets(0, 0, 5, 0);
		gbc_btnRegistro.gridx = 9;
		gbc_btnRegistro.gridy = 0;
		frmLogin.getContentPane().add(btnRegistro, gbc_btnRegistro);
		
		JLabel lblId = new JLabel("ID");
		GridBagConstraints gbc_lblId = new GridBagConstraints();
		gbc_lblId.insets = new Insets(0, 0, 5, 5);
		gbc_lblId.gridx = 3;
		gbc_lblId.gridy = 2;
		frmLogin.getContentPane().add(lblId, gbc_lblId);
		
		txtId = new JTextField();
		GridBagConstraints gbc_txtId = new GridBagConstraints();
		gbc_txtId.gridwidth = 2;
		gbc_txtId.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtId.insets = new Insets(0, 0, 5, 5);
		gbc_txtId.gridx = 5;
		gbc_txtId.gridy = 2;
		frmLogin.getContentPane().add(txtId, gbc_txtId);
		txtId.setColumns(10);
		
		JLabel lblPassword = new JLabel("Contrase\u00F1a");
		GridBagConstraints gbc_lblPassword = new GridBagConstraints();
		gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
		gbc_lblPassword.gridx = 3;
		gbc_lblPassword.gridy = 3;
		frmLogin.getContentPane().add(lblPassword, gbc_lblPassword);
		
		txtPassword = new JPasswordField();
		GridBagConstraints gbc_txtPassword = new GridBagConstraints();
		gbc_txtPassword.gridwidth = 2;
		gbc_txtPassword.insets = new Insets(0, 0, 5, 5);
		gbc_txtPassword.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtPassword.gridx = 5;
		gbc_txtPassword.gridy = 3;
		frmLogin.getContentPane().add(txtPassword, gbc_txtPassword);
		
		btnLogin = new JButton("Login");
		
		
		GridBagConstraints gbc_btnLogin = new GridBagConstraints();
		gbc_btnLogin.insets = new Insets(0, 0, 5, 5);
		gbc_btnLogin.anchor = GridBagConstraints.WEST;
		gbc_btnLogin.gridx = 5;
		gbc_btnLogin.gridy = 4;
		frmLogin.getContentPane().add(btnLogin, gbc_btnLogin);
	}

	public void SetVisible(boolean visible){
		
		frmLogin.setVisible(visible);
	}
	
	public void dispose(){
		this.frmLogin.dispose();
	}

	public void registerListener(ActionListener listener){
		
		this.btnLogin.addActionListener(listener);
		this.btnRegistro.addActionListener(listener);
	}
	@Override
	public void update() {
		// TODO Auto-generated method stub
		
	}
	
	public String getTxtId() {
		return txtId.getText();
	}
	public char[] getTxtPassword() {
		return txtPassword.getPassword();
	}
}
